package com.starlink.controller.wechat;

import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.github.pagehelper.PageInfo;
import com.starlink.model.request.PointsAcquireBillRequest;
import com.starlink.model.request.PointsUseBillRequest;
import com.starlink.model.vo.PointsAcquireBillVO;
import com.starlink.model.vo.PointsVO;
import com.starlink.service.PointsService;
import com.starlink.model.vo.PointsUseBillVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/wechat/bill")
@Api(value = "【小程序端】积分明细模块", tags = {"【小程序端】积分明细模块"})
public class WechatPointsController {

    @Autowired
    private PointsService pointsService;

    @WebAccess(login = true)
    @ApiOperation("积分情况查询")
    @GetMapping("/selectPointInfo")
    public WebResponse<PointsVO> selectPointInfo(@RequestParam("userId")Long userId) {
        return WebResponse.build(pointsService.selectPointInfo(userId));
    }

    @WebAccess(login = true)
    @ApiOperation("积分使用明细分页查询")
    @PostMapping("/pageQueryPointsUseBill")
    public WebResponse<PageInfo<PointsUseBillVO>> pageQueryPointsUseBill(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                                         @RequestBody PointsUseBillRequest request) {
        return WebResponse.build(pointsService.pageQueryPointsUseBill(pageable,request));
    }

    @WebAccess(login = true)
    @ApiOperation("积分获取明细分页查询")
    @PostMapping("/pageQueryPointsAcquireBill")
    public WebResponse<PageInfo<PointsAcquireBillVO>> pageQueryPointsAcquireBill(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                                                 @RequestBody PointsAcquireBillRequest request) {
        return WebResponse.build(pointsService.pageQueryPointsAcquireBill(pageable,request));
    }

    @WebAccess(login = true)
    @ApiOperation("积分增加")
    @PostMapping("/addPoint")
    public WebResponse<Boolean> addPoint(@RequestBody PointsAcquireBillRequest request) {
        return WebResponse.build(pointsService.addPoint(request));
    }
}
